import axios from "axios";
import store from "@/store";

let request = axios.create({
  baseURL: "http://toutiao.itheima.net",
});


// 请求拦截器
request.interceptors.request.use(
  (config) => {
    // 一定要return config
    console.log("请求都走这里", config);
    // 如果你登陆了,就带上token
    if (store.getters.token) {
      config.headers.Authorization = `Bearer ${store.state.user.token}`;
    }
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);
export default request;
